﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BCCommon;
using BCData.WeChatComponent.WeChatNewsImageRecord;
using BCDto.WeChatComponent.WeChatNewsImageRecord;
using BCEntity.WeChatComponent.WeChatNewsImageRecord;
using BCService.Utils;

namespace BCService.WeChatComponent.WeChatNewsImageRecordService
{
    /// <summary>
    /// 微信图文内部图片记录
    /// </summary>
    public class WeChatNewsImageRecordService : IWeChatNewsImageRecordService
    {
        private readonly IWeChatNewsImageRecordData weChatNewsImageRecordData;

        public WeChatNewsImageRecordService(IWeChatNewsImageRecordData weChatNewsImageRecordData)
        {
            this.weChatNewsImageRecordData = weChatNewsImageRecordData;
        }

        public WeChatNewsImageRecordViewDto Add(WeChatNewsImageRecordDto weChatNewsImageRecordDto)
        {
            return this.weChatNewsImageRecordData.Add(weChatNewsImageRecordDto.As<WeChatNewsImageRecordEntity>()).As<WeChatNewsImageRecordViewDto>();
        }

        public WeChatNewsImageRecordViewDto Get(string uploadFileRecordNo)
        {
            return this.weChatNewsImageRecordData.Get(uploadFileRecordNo).As<WeChatNewsImageRecordViewDto>();
        }

        public WeChatNewsImageRecordViewDto Get(long weChatNewsImageRecordId)
        {
            return this.weChatNewsImageRecordData.Get(weChatNewsImageRecordId).As<WeChatNewsImageRecordViewDto>();
        }

        public PageableList<WeChatNewsImageRecordViewDto> Get(DateTime? start, DateTime? end, bool? ascending, int pageIndex = 1, int pageSize = 10)
        {
            var list = this.weChatNewsImageRecordData.Get(start, end, out int dataCount, ascending, pageIndex, pageSize);
            return new PageableList<WeChatNewsImageRecordViewDto>
            {
                Count = dataCount,
                Items = list.Select(p => p.As<WeChatNewsImageRecordViewDto>())
            };
        }
    }
}
